/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.mechanatrix.loco;

import com.jme3.asset.AssetManager;
import com.jme3.asset.AssetNotFoundException;
import com.jme3.material.Material;
import com.jme3.scene.SceneGraphVisitor;
import com.jme3.scene.Spatial;

/**
 *
 * @author Dustin
 */
public class ModelParser implements SceneGraphVisitor {
	
	/**
	 * Model name.
	 */
	private static final String PREFIX = "LOCK_08";
	/**
	 * Model file path.
	 */
	private static final String MODEL = "Models/loco/" + PREFIX + ".obj";
	//Model spatial names
	private static final String CE_BRAKE = PREFIX + "-geom-20";
	private static final String CE_LOWER_ARM = PREFIX + "-geom-18";
	private static final String CE_OUTER_ARM = PREFIX + "-geom-23";
	private static final String CE_UPPER_ARM = PREFIX + "-geom-22";
	private static final String CE_WHEEL_BOX = PREFIX + "-geom-26";
	private static final String CEN_WHEEL = PREFIX + "-geom-63";
	private static final String CES_WHEEL = PREFIX + "-geom-65";
	private static final String CN_AXLE = PREFIX + "-geom-59";
	private static final String CS_AXLE = PREFIX + "-geom-62";
	private static final String CW_BRAKE = PREFIX + "-geom-16";
	private static final String CW_LOWER_ARM = PREFIX + "-geom-14";
	private static final String CW_OUTER_ARM = PREFIX + "-geom-8";
	private static final String CW_UPPER_ARM = PREFIX + "-geom-28";
	private static final String CW_WHEEL_BOX = PREFIX + "-geom-11";
	private static final String CWN_WHEEL = PREFIX + "-geom-40";
	private static final String CWS_WHEEL = PREFIX + "-geom-43";
	private static final String MAIN_BODY = PREFIX + "-geom-31";
	private static final String N_FAN = PREFIX + "-geom-69";
	private static final String N_GUN_ARM = PREFIX + "-geom-x";
	private static final String N_GUN_TURRET = PREFIX + "-geom-27";
	private static final String N_HEADLIGHT = PREFIX + "-geom-41";
	private static final String N_MACHINE_GUN = PREFIX + "-geom-";
	private static final String NE_BRAKE = PREFIX + "-geom-37";
	private static final String NE_CHAIN = PREFIX + "-geom-57";
	private static final String NE_DITCHLIGHT = PREFIX + "-geom-0";
	private static final String NE_HORN = PREFIX + "-geom-45";
	private static final String NE_LOWER_ARM = PREFIX + "-geom-35";
	private static final String NE_LOWER_LIGHT = PREFIX + "-geom-5";
	private static final String NE_OUTER_ARM = PREFIX + "-geom-34";
	private static final String NE_UPPER_ARM = PREFIX + "-geom-29";
	private static final String NE_UPPER_LIGHT = PREFIX + "-geom-4";
	private static final String NE_WHEEL_BOX = PREFIX + "-geom-39";
	private static final String NEN_WHEEL = PREFIX + "-geom-58";
	private static final String NES_WHEEL = PREFIX + "-geom-61";
	private static final String NN_AXLE = PREFIX + "-geom-68";
	private static final String NS_AXLE = PREFIX + "-geom-56";
	private static final String NW_BRAKE = PREFIX + "-geom-19";
	private static final String NW_CHAIN = PREFIX + "-geom-64";
	private static final String NW_DITCHLIGHT = PREFIX + "-geom-1";
	private static final String NW_HORN = PREFIX + "-geom-30";
	private static final String NW_LOWER_ARM = PREFIX + "-geom-21";
	private static final String NW_LOWER_LIGHT = PREFIX + "-geom-";
	private static final String NW_OUTER_ARM = PREFIX + "-geom-24";
	private static final String NW_UPPER_ARM = PREFIX + "-geom-12";
	private static final String NW_UPPER_LIGHT = PREFIX + "-geom-6";
	private static final String NW_WHEEL_BOX = PREFIX + "-geom-17";
	private static final String NWN_WHEEL = PREFIX + "-geom-36";
	private static final String NWS_WHEEL = PREFIX + "-geom-38";
	private static final String OBJECT_NODE = PREFIX + "-objnodex";
	private static final String S_FAN = PREFIX + "-geom-70";
	private static final String S_GUN_ARM = PREFIX + "-geom-71";
	private static final String S_GUN_TURRET = PREFIX + "-geom-25";
	private static final String S_HEADLIGHT = PREFIX + "-geom-2";
	private static final String S_MACHINE_GUN = PREFIX + "-geom-72";
	private static final String SE_BRAKE = PREFIX + "-geom-44";
	private static final String SE_CHAIN = PREFIX + "-geom-55";
	private static final String SE_DITCHLIGHT = PREFIX + "-geom-";
	private static final String SE_HORN = PREFIX + "-geom-10";
	private static final String SE_LOWER_ARM = PREFIX + "-geom-13";
	private static final String SE_OUTER_ARM = PREFIX + "-geom-15";
	private static final String SE_UPPER_ARM = PREFIX + "-geom-54";
	private static final String SE_UPPER_LIGHT = PREFIX + "-geom-67";
	private static final String SE_WHEEL_BOX = PREFIX + "-geom-9";
	private static final String SE_LOWER_LIGHT = PREFIX + "-geom-66";
	private static final String SEN_WHEEL = PREFIX + "-geom-51";
	private static final String SES_WHEEL = PREFIX + "-geom-47";
	private static final String SN_AXLE = PREFIX + "-geom-49";
	private static final String SS_AXLE = PREFIX + "-geom-46";
	private static final String SW_BRAKE = PREFIX + "-geom-52";
	private static final String SW_CHAIN = PREFIX + "-geom-60";
	private static final String SW_HORN = PREFIX + "-geom-3";
	private static final String SW_LOWER_ARM = PREFIX + "-geom-42";
	private static final String SW_LOWER_LIGHT = PREFIX + "-geom-7";
	private static final String SW_OUTER_ARM = PREFIX + "-geom-50";
	private static final String SW_TURNLIGHT = PREFIX + "-geom-";
	private static final String SW_UPPER_ARM = PREFIX + "-geom-48";
	private static final String SW_UPPER_LIGHT = PREFIX + "-geom-";
	private static final String SW_WHEEL_BOX = PREFIX + "-geom-53";
	private static final String SWN_WHEEL = PREFIX + "-geom-32";
	private static final String SWS_WHEEL = PREFIX + "-geom-33";
	
	private Locomotive loco;
	private AssetManager assetManager;

	public ModelParser(Locomotive loco, AssetManager assetManager) {
		this.loco = loco;
		this.assetManager = assetManager;
		try {
			loco.model = assetManager.loadModel(MODEL);
			//Material material = new Material(assetManager, "Common/MatDefs/Misc/ShowNormals.j3md");
			//Material material = new Material(assetManager, "Common/MatDefs/Misc/ShowNormals.j3md");
			//loco.model.setMaterial(material);
		} catch (AssetNotFoundException e) {
			System.err.printf(e.getMessage());
		}
		loco.model.setCullHint(Spatial.CullHint.Never);
	}

	@Override
	public void visit(Spatial spatial) {
				String name = spatial.getName();
				/*
				System.out.printf("Mapping model spatial: %s%n", name);
				if (name.endsWith("-geom-72")) {
					Material material = new Material(assetManager, "Common/MatDefs/Misc/ShowNormals.j3md");
					spatial.setMaterial(material);
				}
				*/
				switch (name) {
					case CE_BRAKE:
						loco.centerBogie.eastWheelBox.breakClamp = spatial;
						break;
					case CE_LOWER_ARM:
						loco.centerBogie.eastWheelBox.lowerArm = spatial;
						break;
					case CE_OUTER_ARM:
						loco.centerBogie.eastWheelBox.outerArm = spatial;
						break;
					case CE_UPPER_ARM:
						loco.centerBogie.eastWheelBox.upperArm = spatial;
						break;
					case CE_WHEEL_BOX:
						loco.centerBogie.eastWheelBox.wheelBox = spatial;
						break;
					case CEN_WHEEL:
						loco.centerBogie.eastWheelBox.northWheel = spatial;
						break;
					case CES_WHEEL:
						loco.centerBogie.eastWheelBox.southWheel = spatial;
						break;
					case CN_AXLE:
						loco.centerBogie.northAxle = spatial;
						break;
					case CS_AXLE:
						loco.centerBogie.southAxle = spatial;
						break;
					case CW_BRAKE:
						loco.centerBogie.westWheelBox.breakClamp = spatial;
						break;
					case CW_LOWER_ARM:
						loco.centerBogie.westWheelBox.lowerArm = spatial;
						break;
					case CW_OUTER_ARM:
						loco.centerBogie.westWheelBox.outerArm = spatial;
						break;
					case CW_UPPER_ARM:
						loco.centerBogie.westWheelBox.upperArm = spatial;
						break;
					case CW_WHEEL_BOX:
						loco.centerBogie.westWheelBox.wheelBox = spatial;
						break;
					case CWN_WHEEL:
						loco.centerBogie.westWheelBox.northWheel = spatial;
						break;
					case CWS_WHEEL:
						loco.centerBogie.westWheelBox.southWheel = spatial;
						break;
					case OBJECT_NODE:
						loco.objectNode = spatial;
						break;
					case MAIN_BODY:
						loco.mainBody = spatial;
						break;
					case NE_BRAKE:
						loco.northBogie.eastWheelBox.breakClamp = spatial;
						break;
					case NE_LOWER_ARM:
						loco.northBogie.eastWheelBox.lowerArm = spatial;
						break;
					case NE_OUTER_ARM:
						loco.northBogie.eastWheelBox.outerArm = spatial;
						break;
					case NE_UPPER_ARM:
						loco.northBogie.eastWheelBox.upperArm = spatial;
						break;
					case NE_WHEEL_BOX:
						loco.northBogie.eastWheelBox.wheelBox = spatial;
						break;
					case NEN_WHEEL:
						loco.northBogie.eastWheelBox.northWheel = spatial;
						break;
					case NES_WHEEL:
						loco.northBogie.eastWheelBox.southWheel = spatial;
						break;
					case NN_AXLE:
						loco.northBogie.northAxle = spatial;
						break;
					case NS_AXLE:
						loco.northBogie.southAxle = spatial;
						break;
					case NW_BRAKE:
						loco.northBogie.westWheelBox.breakClamp = spatial;
						break;
					case NW_CHAIN:
						loco.northEnd.westChain = spatial;
						break;
					case NW_LOWER_ARM:
						loco.northBogie.westWheelBox.lowerArm = spatial;
						break;
					case NW_OUTER_ARM:
						loco.northBogie.westWheelBox.outerArm = spatial;
						break;
					case NW_UPPER_ARM:
						loco.northBogie.westWheelBox.upperArm = spatial;
						break;
					case NW_WHEEL_BOX:
						loco.northBogie.westWheelBox.wheelBox = spatial;
						break;
					case NWN_WHEEL:
						loco.northBogie.westWheelBox.northWheel = spatial;
						break;
					case NWS_WHEEL:
						loco.northBogie.westWheelBox.southWheel = spatial;
						break;
					case N_FAN:
						loco.northEnd.fan = spatial;
						break;
					case N_GUN_TURRET:
						loco.northEnd.gunTurret = spatial;
						break;
					case SE_BRAKE:
						loco.southBogie.eastWheelBox.breakClamp = spatial;
						break;
					case SE_CHAIN:
						loco.southEnd.eastChain = spatial;
						break;
					case SE_LOWER_ARM:
						loco.southBogie.eastWheelBox.lowerArm = spatial;
						break;
					case SE_OUTER_ARM:
						loco.southBogie.eastWheelBox.outerArm = spatial;
						break;
					case SE_UPPER_ARM:
						loco.southBogie.eastWheelBox.upperArm = spatial;
						break;
					case SE_WHEEL_BOX:
						loco.southBogie.eastWheelBox.wheelBox = spatial;
						break;
					case SEN_WHEEL:
						loco.southBogie.eastWheelBox.northWheel = spatial;
						break;
					case SES_WHEEL:
						loco.southBogie.eastWheelBox.southWheel = spatial;
						break;
					case SN_AXLE:
						loco.southBogie.northAxle = spatial;
						break;
					case SS_AXLE:
						loco.southBogie.southAxle = spatial;
						break;
					case SW_BRAKE:
						loco.southBogie.westWheelBox.breakClamp = spatial;
						break;
					case NE_CHAIN:
						loco.northEnd.eastChain = spatial;
						break;
					case SW_CHAIN:
						loco.southEnd.westChain = spatial;
						break;
					case SW_LOWER_ARM:
						loco.southBogie.westWheelBox.lowerArm = spatial;
						break;
					case SW_OUTER_ARM:
						loco.southBogie.westWheelBox.outerArm = spatial;
						break;
					case SW_UPPER_ARM:
						loco.southBogie.westWheelBox.upperArm = spatial;
						break;
					case SW_WHEEL_BOX:
						loco.southBogie.westWheelBox.wheelBox = spatial;
						break;
					case SWN_WHEEL:
						loco.southBogie.westWheelBox.northWheel = spatial;
						break;
					case SWS_WHEEL:
						loco.southBogie.westWheelBox.southWheel = spatial;
						break;
					case S_FAN:
						loco.southEnd.fan = spatial;
						break;
					case S_GUN_TURRET:
						loco.southEnd.gunTurret = spatial;
						break;
				}
	}
	
}
